/*
 * License GNU LGPL
 * Copyright (C) 2012 Amrullah <amrullah@panemu.com>.
 */
package com.abc.cheque.ui;

i
import java.util.ArrayList;
import java.util.List;

import javafx.scene.control.TableColumn;

import com.abc.cheque.common.TableCriteria;
import com.abc.cheque.common.TableData;
import com.abc.cheque.entity.Contact;
import com.abc.cheque.test.DaoBase;
import com.abc.cheque.ui.table.TableController;


/**
 *
 * @author Amrullah <amrullah@panemu.com>
 */
public class InRowMaintenanceController extends TableController<Contact> {

    private DaoBase<Person> daoPerson = new DaoBase<>(Contact.class);

    @Override
    public TableData loadData(int startIndex, List<TableCriteria> filteredColumns, List<String> sortedColumns, List<TableColumn.SortType> sortingOrders, int maxResult) {
        boolean join = true;
//        for (TableCriteria crit : filteredColumns) {
//            if (crit.getAttributeName().equals(Person_.insurance.getName()) && crit.getOperator() == Operator.is_null) {
//                join = false;
//                break;
//            }
//        }
        List<String> lstJoin = new ArrayList<>();
        if (join) {
            lstJoin.add(Person_.insurance.getName());
        }
        TableData result = daoPerson.fetch(startIndex, filteredColumns, sortedColumns, sortingOrders, maxResult, lstJoin);
        return result;
    }

    @Override
    public List<Person> insert(List<Person> newRecords) {
        return daoPerson.insert(newRecords);
    }

    @Override
    public List<Person> update(List<Person> records) {
        List<Person> result = daoPerson.update(records);
        result = daoPerson.initRelationship(records, Person_.insurance.getName());
        return result;
    }

    @Override
    public void delete(List<Person> records) {
        daoPerson.delete(records);
    }
}
